package com.warmlight.voicepacket.ui.communitylm.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.base.SingleRecycleViewAdapter;

import java.util.Map;

public class ReportRecyclerAdapter extends SingleRecycleViewAdapter<Map<String,String>> {

    public ReportRecyclerAdapter(Context context) {
        super(context);
    }

    @Override
    public HashViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_report_item,parent,false);
        HashViewHolder viewHolder = new HashViewHolder(view);
        viewHolder.putView(R.id.tv_report_item);
        return viewHolder;
    }

    /**
     * {"code":200,"time":1536201229,"msg":"",
     * "data":[{"id":0,"reason_desc":"低俗色情"},{"id":1,"reason_desc":"政治敏感"},
     * {"id":2,"reason_desc":"违法犯罪"},{"id":3,"reason_desc":"广告营销"},
     * {"id":4,"reason_desc":"侮辱谩骂"},{"id":5,"reason_desc":"引起不适"},
     * {"id":6,"reason_desc":"其它不当内容"}]}
     * @param holder
     * @param position
     */
    @Override
    public void onBindViewHolder(HashViewHolder holder, int position) {
        final Map<String, String> item = getItem(position);
        TextView tv_report_item = (TextView) holder.findView(R.id.tv_report_item);
        final String id = item.get("id");
        String msg = item.get("reason_desc");
        tv_report_item.setText(msg);
        final String select = item.get("select");
        if (TextUtils.equals("1",select)){
            tv_report_item.setSelected(true);
        }else{
            tv_report_item.setSelected(false);
        }

        tv_report_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.equals("0",select)){
                    item.put("select","1");
                }else{
                    item.put("select","0");
                }
                notifyDataSetChanged();
            }
        });
    }

}
